package com.example.controller;


import cn.hutool.core.util.XmlUtil;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.w3c.dom.Document;

import javax.xml.xpath.XPathConstants;
import java.util.Date;


/**
 * @author ChenXiaoBin
 * on 2019-06-26
 */
@RestController
@RequestMapping("/V1.0/json")
public class ALiJsonController {

    @PutMapping("")
    @ApiOperation(value = "json", notes = "json")
    public void jsonStringChange() {



        XStream xStream = new XStream(new DomDriver());
//        //为类名节点重命名
//        xStream.alias("persion", com.example.entity.persion.Persion.class);
//        String xml = "<persion>\n" +
//                "  <id>123</id>\n" +
//                "  <name type= \"1\">fdfee</name>\n" +
//                "  <gender>true</gender>\n" +
//                "  <birthday>2019-06-26 14:25:44.153 UTC</birthday>\n" +
//                "</persion>";
//        Persion persion = (Persion) xStream.fromXML(xml);
//
//
//        Document document = XmlUtil.parseXml(xml);
//        Object value = XmlUtil.getByXPath("//persion/id", document, XPathConstants.STRING);

        String xml = "<TimelineObject>\n" +
                "    <id>\n" +
                "        <![CDATA[13099149171829387400]]>\n" +
                "    </id>\n" +
                "    <username>\n" +
                "        <![CDATA[wxid_k19jbob6eg4h22]]>\n" +
                "    </username>\n" +
                "    <createTime>\n" +
                "        <![CDATA[1561540266]]>\n" +
                "    </createTime>\n" +
                "    <contentDescShowType>0</contentDescShowType>\n" +
                "    <contentDescScene>0</contentDescScene>\n" +
                "    <private>\n" +
                "        <![CDATA[0]]>\n" +
                "    </private>\n" +
                "    <contentDesc>\n" +
                "        <![CDATA[ºìÊ÷ÁÖ¸ß²ã¿´½\u00ADÈý²ã¸´Ê½£¡4·¿£¡208Íò¡£½ðÉ½»¹ÓÐÂð£¿¸£ÖÝ»¹ÓÐÂð£¿]]>\n" +
                "    </contentDesc>\n" +
                "    <contentattr>\n" +
                "        <![CDATA[0]]>\n" +
                "    </contentattr>\n" +
                "    <sourceUserName></sourceUserName>\n" +
                "    <sourceNickName></sourceNickName>\n" +
                "    <statisticsData></statisticsData>\n" +
                "    <weappInfo>\n" +
                "        <appUserName>0</appUserName>\n" +
                "        <pagePath></pagePath>\n" +
                "    </weappInfo>\n" +
                "    <canvasInfoXml></canvasInfoXml>\n" +
                "    <ContentObject>\n" +
                "        <contentStyle>\n" +
                "            <![CDATA[15]]>\n" +
                "        </contentStyle>\n" +
                "        <contentSubStyle>\n" +
                "            <![CDATA[0]]>\n" +
                "        </contentSubStyle>\n" +
                "        <title>Î¢ÐÅÐ¡ÊÓÆµ</title>\n" +
                "        <description></description>\n" +
                "        <contentUrl>https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&amp;v=1</contentUrl>\n" +
                "        <mediaList>\n" +
                "            <media>\n" +
                "                <id>\n" +
                "                    <![CDATA[13099149172409381005]]>\n" +
                "                </id>\n" +
                "                <type>\n" +
                "                    <![CDATA[6]]>\n" +
                "                </type>\n" +
                "                <title>\n" +
                "                    <![CDATA[ºìÊ÷ÁÖ¸ß²ã¿´½\u00ADÈý²ã¸´Ê½£¡4·¿£¡208Íò¡£½ðÉ½»¹ÓÐÂð£¿¸£ÖÝ»¹ÓÐÂð£¿]]>\n" +
                "                </title>\n" +
                "                <description>\n" +
                "                    <![CDATA[ºìÊ÷ÁÖ¸ß²ã¿´½\u00ADÈý²ã¸´Ê½£¡4·¿£¡208Íò¡£½ðÉ½»¹ÓÐÂð£¿¸£ÖÝ»¹ÓÐÂð£¿]]>\n" +
                "                </description>\n" +
                "                <private>\n" +
                "                    <![CDATA[0]]>\n" +
                "                </private>\n" +
                "                <url videomd5=\"e370f6c8a7c017fce2fcafc88ea7d89d\" type=\"1\" md5=\"a8ed1258d7d17101fb8ca2e69a611d36\">\n" +
                "                    <![CDATA[http://shzjwxsns.video.qq.com/102/20202/snsvideodownload?filekey=30340201010420301e020166040253480410a8ed1258d7d17101fb8ca2e69a611d3602031136ae040d00000004627466730000000131&hy=SH&storeid=32303139303632363137313130343030303634313936613737363234346236376132333330613030303030303636&dotrans=2&ef=15_0&bizid=1023]]>\n" +
                "                </url>\n" +
                "                <thumb type=\"1\">\n" +
                "                    <![CDATA[http://vweixinthumb.tc.qq.com/150/20250/snsvideodownload?filekey=30340201010420301e02020096040253480410886f3f74f2d8bcdb1c0f07724815774302024717040d00000004627466730000000131&hy=SH&storeid=32303139303632363137313130343030303632643265613737363234346236376132333330613030303030303936&bizid=1023]]>\n" +
                "                </thumb>\n" +
                "                <size totalSize=\"18199.0\" width=\"239.0\" height=\"512.0\"></size>\n" +
                "            </media>\n" +
                "        </mediaList>\n" +
                "    </ContentObject>\n" +
                "    <actionInfo>\n" +
                "        <appMsg>\n" +
                "            <mediaTagName></mediaTagName>\n" +
                "            <messageExt></messageExt>\n" +
                "            <messageAction></messageAction>\n" +
                "        </appMsg>\n" +
                "    </actionInfo>\n" +
                "    <appInfo>\n" +
                "        <id></id>\n" +
                "    </appInfo>\n" +
                "    <location poiClassifyId=\"\" poiName=\"\" poiAddress=\"\" poiClassifyType=\"0\" city=\"\"></location>\n" +
                "    <publicUserName></publicUserName>\n" +
                "    <streamvideo>\n" +
                "        <streamvideourl></streamvideourl>\n" +
                "        <streamvideothumburl></streamvideothumburl>\n" +
                "        <streamvideoweburl></streamvideoweburl>\n" +
                "    </streamvideo>\n" +
                "</TimelineObject>";


//        BufferInfo bufferInfo = (BufferInfo) xStream.fromXML(xml);


        Document document = XmlUtil.parseXml(xml);
        Object value = XmlUtil.getByXPath("//TimelineObject/weappInfo/appUserName", document, XPathConstants.STRING);

        String v = value.toString();
        String f = v.trim();
        XmlUtil.getByXPath("//TimelineObject/weappInfo", document, XPathConstants.STRING);
    }

}
